<template>
  <a-modal
    :title="title"
    :width="width"
    :visible="visible"
    :maskClosable="false"
    @cancel="handleCancel"
    v-drag
  >
  <a-spin :spinning="confirmLoading">
     <div style="margin: 0 0 15px 15px;">
      {{$t('商品编码')}}： <span style="font-weight: bold;">{{info.goodsCode}} </span>
        <span style="margin-left:10px">{{$t('商品名称')}}：<span style="font-weight: bold;">{{info.goodsId_dictText}}</span></span>
      </div>
     <a-table
        :columns="columns"
        :dataSource="dataSource"
        size="middle"
        bordered
        class="j-table-force-nowrap"
        :pagination="false"
        style="padding-left: 11px"
      ></a-table>
  </a-spin>
  <template slot="footer">
    <a-button @click="handleCancel">{{$t('关闭')}}</a-button>
  </template>
  </a-modal>
</template>

<script>
import { getAction } from '@/api/manage'
let that
export default {
  name: 'InventoryDetailModal',
  components: {
  },
  data() {
    return {
      title: '',
      width: 800,
      visible: false,
      confirmLoading:false,
      dataSource: [],
      dataForm:{},
      columns: [
        {
          title: this.$t('序号'),
          dataIndex: '',
          key: 'rowIndex',
          align: 'center',
          width: 100,
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: this.$t('仓库名称'),
          dataIndex: 'storeId_dictText',
          align: 'center',
        },
        {
          title: this.$t('库存数量'),
          dataIndex: 'stock',
          align: 'center',
          customRender: (t, r) => {
            return t.toFixed(0)
          },
          customCell: function (record, rowIndex) {
            return {
              style: {
                textAlign: 'right',
              },
            }
          }
        },
      ],
      url: {
        list:'/goods/bisGoodsStock/list'
      },
      totalNum: 0,
      totalAmo: 0,
      state: 0,
      info:{},
    }
  },
  methods: {
    edit(record) {
      this.visible = true
      this.info = record
      let query = {}
      query. goodsId =  record.goodsId
      query.goodsCode = record.goodsCode
      query.storeId = record.storeId
      query.pageNo = 1
      query.pageSize = 9999
      getAction(this.url.list, query).then((res) => {
        if (res.success) {
          this.dataSource = res.result.records
          let totalStock = 0;
          this.dataSource.forEach((col) => {
            totalStock += col.stock
          })
          this.dataSource.push({
            storeId_dictText: '合计',
            stock: totalStock,
          })
        }
      })
    },
    handleCancel() {
      this.visible = false
    },
  },
}
</script>

<style scoped>
</style>